package org.example.design.designmode.decoratorpattern.jsonlogger;

import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;

import java.util.Arrays;

/**
 * 针对logger装饰器实现的扩展类
 *   继承扩展类选择需要扩展的接口
 */
public class JSONLogger extends JsonDecorator {


    public JSONLogger(Logger logger) {
        super(logger);
    }

    @Override
    public void info(String s) {
        JSONObject object = newJsonObject();
        object.put("message",s);
        logger.info(object.toString());

    }

    @Override
    public void error(String s) {
        JSONObject object = newJsonObject();
        object.put("message",s);

        logger.info(object.toString());
    }

    public void error(Exception s) {
        JSONObject object = newJsonObject();
        object.put("message",s);
        String exmes = Arrays.toString(s.getStackTrace());
        object.put("exection",exmes);
        logger.info(object.toString());
    }



    public JSONObject newJsonObject(){
        return  new JSONObject();
    }
}
